#pragma once

#include <json/json.h>
#include <opencv2/core/core.hpp>
#include <opencv2/core/ocl.hpp>
#include <opencv2/core/utils/logger.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc_c.h>
#include <opencv2/imgproc/types_c.h>
#include <opencv2/opencv.hpp>
#include <opencv2/video/tracking.hpp>

struct Pixel
{
  int PointNumber;
  double PixX;
  double PixY;
};

struct DetectionResult
{
  cv::Mat img;
  int num_points;
  std::vector<cv::Point2f> coordinates;
};

class ImageHandle
{
private:
  /* data */
public:
  //
  cv::Mat Binarization(cv::Mat img, int thresh = 70, int maxval = 255);
  cv::Mat BrightnessEnforce(cv::Mat img, double alpha = 1.1, double beta = 0);
  cv::Mat Color2Gray(cv::Mat img);

  // 圆检测
  DetectionResult CircleRecognition(cv::Mat &img_raw,
                                    cv::Rect &roiRect,
                                    cv::Mat &img,
                                    std::vector<cv::Vec3f> &circles,
                                    int minDst, int threshold1,
                                    int threshold2, int minRadius,
                                    int maxRadius);

  // 矩形检测
  DetectionResult RectangleRecognition(cv::Mat img,
                                       int threshold1,
                                       int threshold2,
                                       int minArea = 50,
                                       int maxArea = 0);

  // 模板匹配
  DetectionResult PatternRecognition(cv::Mat inputImg,
                                     const cv::Mat &inputTempl,
                                     int rectangleColor = 255,
                                     int rectangleThickness = 5); // 使用轮廓匹配的模板匹配

  char *ImageBase64Encode(cv::Mat image); // 将图像用base64编码，返回字符串指针
  std::string Image2json(cv::Mat image);  // 将图像用base64编码后序列化为json字符串
};
